<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>新增职位</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css">
</head>
<body>
    <div th:replace="common/header :: header"></div>

    <div class="container mt-5">
        <div class="card shadow rounded-4">
            <div class="card-header bg-success text-white rounded-top-4">
                <h5 class="mb-0"><i class="bi bi-plus-circle"></i> 新增职位</h5>
            </div>
            <div class="card-body">
                <form id="jobForm" onsubmit="return submitForm(event)">
                    <div class="row mb-3">
                        <div class="col-md-6">
                            <label class="form-label">职位名称 <span class="text-danger">*</span></label>
                            <input type="text" class="form-control rounded-pill" name="title" required>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label">部门 <span class="text-danger">*</span></label>
                            <select class="form-select rounded-pill" name="department" required>
                                <option value="">选择部门</option>
                                <option th:each="dept : ${departments}" th:value="${dept}" th:text="${dept}"></option>
                            </select>
                        </div>
                    </div>
                    <div class="row mb-3">
                        <div class="col-md-6">
                            <label class="form-label">最低薪资(K) <span class="text-danger">*</span></label>
                            <input type="number" class="form-control rounded-pill" name="salaryMin" required min="0">
                        </div>
                        <div class="col-md-6">
                            <label class="form-label">最高薪资(K) <span class="text-danger">*</span></label>
                            <input type="number" class="form-control rounded-pill" name="salaryMax" required min="0">
                        </div>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">职位描述 <span class="text-danger">*</span></label>
                        <textarea class="form-control rounded-3" name="description" rows="4" required></textarea>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">任职要求 <span class="text-danger">*</span></label>
                        <textarea class="form-control rounded-3" name="requirements" rows="4" required></textarea>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">状态</label>
                        <div class="form-check form-check-inline">
                            <input class="form-check-input" type="radio" name="status" value="OPEN" checked>
                            <label class="form-check-label">招聘中</label>
                        </div>
                        <div class="form-check form-check-inline">
                            <input class="form-check-input" type="radio" name="status" value="CLOSED">
                            <label class="form-check-label">已结束</label>
                        </div>
                    </div>
                    <div class="text-center">
                        <button type="submit" class="btn btn-success rounded-pill px-4 me-2">
                            <i class="bi bi-save"></i> 保存
                        </button>
                        <button type="button" class="btn btn-outline-secondary rounded-pill px-4" onclick="history.back()">
                            <i class="bi bi-x"></i> 取消
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <script>
        function submitForm(event) {
            event.preventDefault();
            
            const form = document.getElementById('jobForm');
            const formData = new FormData(form);
            const data = Object.fromEntries(formData.entries());
            
            // 验证薪资范围
            if (parseInt(data.salaryMin) > parseInt(data.salaryMax)) {
                alert('最低薪资不能大于最高薪资');
                return false;
            }

            axios.post('/job/add', data)
                .then(response => {
                    alert('保存成功');
                    location.href = '/job/list';
                })
                .catch(error => {
                    alert('保存失败：' + (error.response?.data?.message || '未知错误'));
                });

            return false;
        }
    </script>
</body>
</html> 